package persentation.presentAdministrator;

import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

import persentation.presentLogin.LoginFrame;

import po.userPO.UserPO;
import dataservice.userDataService.UserDatabaseService;
import businesslogic.courseBl.CourseController;
import businesslogic.userBl.AdministratorController;

import java.awt.Color;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;



public class AdministratorFrame extends JFrame{
	private JPanel contentPane;
	private Title title;
	private ButtonPanel buttonPanel;
	private MyTabbedPane tabbedPane;
	private ChangePasswordPanel changePasswordPanel;
	private DeleteUserPanel deleteUserPanel;
	private AddUserPanel addUserPanel;
	private ShowUserPanel showUserPanel;
	private CourseController courseController;
	
	private ImageIcon addIcon;
	private JLabel addIconLabel;
	private ImageIcon showIcon;
	private JLabel showIconLabel;
	private ImageIcon deleteIcon;
	private JLabel deleteIconLabel;
	private ImageIcon passwordIcon;
	private JLabel passwordIconLabel;
	private String userName;
	private BottomPanel bottomPanel;
		
	private AdministratorController administratorController;
	
	public static void main(String[] args) {
	
		UIManager.put("RootPane.setupButtonVisible", false);
		BeautyEyeLNFHelper.translucencyAtFrameInactive=false;
		try{
			
			org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
		}catch(Exception e){
			e.printStackTrace();
		}
		
		
		EventQueue.invokeLater(new Runnable(){
			public void run(){
				try{
					AdministratorFrame frame=new AdministratorFrame("admin");
					
					frame.setVisible(true);
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		});
		
		
	}
	
	
	
public	AdministratorFrame(String ID){
	courseController=new CourseController(ID);
	administratorController=new AdministratorController();
	changePasswordPanel=new ChangePasswordPanel(ID);
	
	addUserPanel=new AddUserPanel(courseController);
	deleteUserPanel=new DeleteUserPanel(courseController);

	showUserPanel=new ShowUserPanel(courseController);
	
	deleteUserPanel.setShowPanel(showUserPanel);
	
	
	setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	this.setResizable(false);
	setTitle("南京大学选课系统");
	setSize(1100,750);
	Toolkit toolkit=Toolkit.getDefaultToolkit();
	Dimension screen=toolkit.getScreenSize();
	int x=(int)(screen.getWidth()-this.getWidth())>>1;
	int y=(((int) ((screen.getHeight()-this.getHeight())-15)>>1));
	setLocation(x,y);
	contentPane=new JPanel();
	contentPane.setBorder(new EmptyBorder(5,5,5,5));
	setContentPane(contentPane);
	contentPane.setLayout(null);

	title=new Title("管理员");
	title.setSize(1100, 71);
	getContentPane().add(title);
	title.setLocation(0, 0);	
	
	
	try {
		userName=administratorController.getUserName(ID);
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
		ExceptionHandler.networkException();
	}
	bottomPanel=new BottomPanel(userName);
	
	tabbedPane = new MyTabbedPane();
	tabbedPane.addBottom(bottomPanel);
	showUserPanel.setTabbedPane(tabbedPane);
	tabbedPane.addOne("欢迎使用", bottomPanel);
	tabbedPane.setBounds(220,70,880,641);
	contentPane.add(tabbedPane);
//	tabbedPane.addCloseListener(new ActionListener(){
//		public void actionPerformed(ActionEvent e){
//			if(e.getActionCommand().equals("ON_TAB_CLOSE")){   
//            	int index=tabbedPane.getSelectedIndex();
//                tabbedPane.removeTabAt(index);   
//        
//                tabbedPane.removeOne(index);
//                if (tabbedPane.getTabCount()==0) {
//					tabbedPane.addOne("欢迎使用",bottomPanel);
//				}
//                
//            }   
//			
//		}
//	});
	
	buttonPanel=new ButtonPanel();
	buttonPanel.setBackground(Color.WHITE);
	getContentPane().add(buttonPanel);
	buttonPanel.setLocation(0,60);
	
	
	JButton btnNewButton = new JButton("         添加用户");
	btnNewButton.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			tabbedPane.addOne("添加用户", addUserPanel);
		}
	});
	addUserPanel.setShowPanel(showUserPanel);
	btnNewButton.setBounds(10, 41, 170,50);
	buttonPanel.add(btnNewButton,0);
	btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 20));
	
	addIcon=new ImageIcon("Graphics/adminGraphics/add.png");
	addIconLabel=new JLabel(addIcon);
	addIconLabel.setBounds(0, 22, 60, 60);
	btnNewButton.add(addIconLabel);
	
	JButton button_3 = new JButton("         修改密码");
	button_3.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			tabbedPane.addOne("修改密码", changePasswordPanel);
		}
	});
	button_3.setBounds(10, 254, 170,50);
	buttonPanel.add(button_3,0);
	button_3.setFont(new Font("微软雅黑", Font.BOLD, 20));
	
	passwordIcon=new ImageIcon("Graphics/adminGraphics/password.png");
	passwordIconLabel=new JLabel(passwordIcon);
	passwordIconLabel.setBounds(0, 235, 60, 60);
	button_3.add(passwordIconLabel);
	
	JButton button_1 = new JButton("      查看与修改");
	button_1.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			tabbedPane.addOne("查看用户信息", showUserPanel);
		}
	});
	button_1.setBounds(10, 112, 170,50);
	buttonPanel.add(button_1,0);
	button_1.setFont(new Font("微软雅黑", Font.BOLD, 20));
	showIcon=new ImageIcon("Graphics/adminGraphics/student.png");
	showIconLabel=new JLabel(showIcon);
	showIconLabel.setBounds(0, 93, 60, 60);
	button_1.add(showIconLabel);
	
	JButton button = new JButton("         删除用户");
	button.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			tabbedPane.addOne("删除用户", deleteUserPanel);
		}
	});
	button.setBounds(10, 183, 170,50);
	buttonPanel.add(button,0);
	button.setFont(new Font("微软雅黑", Font.BOLD, 20));
	
	deleteIcon=new ImageIcon("Graphics/adminGraphics/delete.png");
	deleteIconLabel=new JLabel(deleteIcon);
	deleteIconLabel.setBounds(0, 164, 60, 60);
	button.add(deleteIconLabel);
	

	new ExceptionHandler(this, new LoginFrame());
	
	}
	

}
